package tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import org.junit.Before;
import org.junit.Test;

import urbanparks.JobDuration;
/**
 * a test class used to ensure method correctness within the Job Duration class.
 * @author Ben Hadorn
 * @version Winter-2012
 */
public class JobDurationTest {
  JobDuration future_date;
  JobDuration past_date;

  /**
   * Initializes 2 test durations before each test.
   */
  @Before
  public void initilizeData() {
    future_date = new JobDuration(2012, 2, 12, 2);
    past_date = new JobDuration(2011, 1, 12, 2);
  }
  /**
   * ensures get start day returns correctly
   */
  @Test
  public void testGetStartDay() {
    assertSame("not the same day of the week", 12, future_date.getDay());
  }
  /**
   * ensures get job length returns correctly
   */
  @Test
  public void testGetJobLength() {
    assertEquals("job lenght incorrect", 2, future_date.getJobLength());
  }
  /**
   * tests to ensure that both past and future jobs return correct boolean.
   */
  @Test
  public void testIsPastJob() {
    assertFalse("job is in the past", future_date.isPastJob());
    assertTrue("job is not in the past", past_date.isPastJob());
  }
  /**
   * ensures get start month returns correctly
   */
  @Test
  public void testGetMonth() {
    assertSame("month set incorrectly", Calendar.MARCH, future_date.getMonth());
  }
  /**
   * ensures get start year returns correctly
   */
  @Test
  public void testGetYear() {
    assertEquals("year set incorrectly", 2012, future_date.getYear());
  }
  /**
   * ensures that the start time returned from this method is a correct
   * representation of the start date.
   */
  @Test
  public void testGetStartTime() {
    Calendar tmp = Calendar.getInstance();
    tmp.set(Calendar.MONTH, future_date.getMonth());
    tmp.set(Calendar.DATE, 12);
    tmp.set(Calendar.YEAR, future_date.getYear());
    assertEquals("dates don't match", tmp.getTime().getTime(), future_date.getStartTime().getTime());
  }
  /**
   * ensures that the correct day of the year is returned.
   */
  @Test
  public void testGetDayOfYear() {
    assertEquals("day of the year not equal", 72, future_date.getDayOfYear());
  }
  /**
   * tests that the toString method returns correctly formatted dates
   * for comparison.
   */
  @Test
  public void testToString() {
    DateFormat simple = new SimpleDateFormat("MM-dd-yyyy");
    System.out.print(future_date);
    assertEquals("string doesn't match", simple.format(future_date.getStartTime().getTime()), future_date.toString() );
  }

}
